Return to doc.sitecore.com

Documentation

 

1.  Introduction

Sitecore is architected to make integration with external data sources easy.  In fact, it is very straight-forward to connect external data sources so that the data they hold can be included in a Sitecore web site using Sitecore standard’s rendering technologies, such as XSLT and .NET web controls. Furthermore, data integrated data sources can be viewed and modified in the Sitecore clients exactly as if they were stored in a Sitecore database.

The Xml data provider presented here is used for the integration of external data sources stored in XML format. The provider is a read-only data provider and supports viewing functionality only.

2.  Installation Guide

The Xml Data Provider is distributed as a standard Sitecore package; hence in order to start using it, you should install the package. Please refer to the 'Installing Modules and Packages' article if you are not familiar with the standard Sitecore Packager tool.

After the package installation, modify the web.config file. 

Please, refer to the ‘Configuration’ section of the ‘Integrating External Data Sources’ article, if you are not familiar with the integration of external data sources.

 

2.1.  Step 1

Add the xml data provider to the dataProviders section of the web.config file, as shown in the example below:

<!-- DATA PROVIDERS -->
<dataProviders>
...
<xmlDataProvider type="Sitecore.Data.DataProviders.XmlDataProvider, Sitecore.XmlDataProvider">
        
<param desc="Cache size">50000000</param>
</xmlDataProvider>
...
</dataProviders>

The provider processes one parameter (see <param> tag). Value of this parameter defines the size in bytes of cache which will be created to store external data.

2.2.  Step 2

Include Xml data provider to the chain of providers in Web and Master databases (be careful, other databases shouldn’t use xml data provider).

<!-- DATABASES -->
<databases>
...
<!-- master -->
<database id="master" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
        
<param desc="name">$(id)</param>
        
        
<dataProviders hint="list:AddDataProvider">
          
<dataProvider ref="dataProviders/main" param1="$(id)"/>
          
<dataProvider ref="dataProviders/xmlDataProvider"/>          
        
</dataProviders>

</database>
...
<!-- web -->
<database id="web" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
<param desc="name">$(id)</param>

<dataProviders hint="list:AddDataProvider">
          
<dataProvider ref="dataProviders/main" param1="$(id)">
            
<disableGroup>publishing</disableGroup>
          
</dataProvider>
          
<dataProvider ref="dataProviders/xmlDataProvider"/>          
        
</dataProviders>
</database>
...
</databases>

Note that Xml data provider will be called last (after the main data provider).

3.  Installation Guide (Sitecore 5.3.1 version)

The Xml Data Provider is distributed as a standard Sitecore package; hence in order to start using it, you should install the package. Please refer to the 'Installing Modules and Packages' article if you are not familiar with the standard Sitecore Packager tool.

After the package installation, modify the web.config file. 

Please, refer to the ‘Configuration’ section of the ‘Integrating External Data Sources’ article, if you are not familiar with the integration of external data sources.

 

3.1.  Step 1

Add the xml data provider to the dataProviders section of the web.config file, as shown in the example below:

<!-- DATA PROVIDERS -->
<dataProviders>
...
<xmlDataProvider type="Sitecore.Data.DataProviders.XmlDataProvider, Sitecore.XmlDataProvider">
        
<param desc="Cache size">50000000</param>
</xmlDataProvider>
...
</dataProviders>

The provider processes one parameter (see <param> tag). Value of this parameter defines the size in bytes of cache which will be created to store external data.

3.2.  Step 2

Include Xml data provider to the chain of providers in Master database.

<!-- DATABASES -->
<databases>
...
<!-- master -->
<database id="master" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
        
<param desc="name">$(id)</param>
        
        
<dataProviders hint="list:AddDataProvider">
          
<dataProvider ref="dataProviders/main" param1="$(id)"/>
          
<dataProvider ref="dataProviders/xmlDataProvider"/>          
        
</dataProviders>

</database>
...
</databases>

Note that Xml data provider will be called last (after the main data provider).

4.  General Description

The Xml data provider from this package allows users to retrieve data from the sources in XML format and integrates this data into Sitecore content manager. The provider works with XML files, structure of which is similar to Sitecore Item structure. Below you can see an example of such XML file:

<items>
  
<field key="title">
    
<content>Liftoff News</content>
  
</field>
  
<field key="link">
    
<content>http://liftoff.msfc.nasa.gov/</content>
  
</field>
  
<item name="Star City" id="Star City">
    
<version language="en" version="1">
      
<fields>
        
<field key="title">
          
<content>Star City</content>
        
</field>
      
</fields>
    
</version>
  
</item>
  
<item name="Name is not specified2" id="632687882347656250">
    
<version language="en" version="1">
      
<fields>
        
<field key="description">
          
<content>Sky watchers in Europe, Asia, and parts of Alaska and Canada will experience a &lt;a href="http://science.nasa.gov/headlines/y2003/30may_solareclipse.htm"&gt;partial eclipse of the Sun&lt;/a&gt; on Saturday, May 31st.</content>
        
</field>
        
<field key="guid">
          
<content>http://liftoff.msfc.nasa.gov/2003/05/30.html#item572</content>
        
</field>
      
</fields>
    
</version>
  
</item>
  
<item name="The Engine That Does More" id="The Engine That Does More">
    
<version language="en" version="1">
      
<fields>
        
<field key="title">
          
<content>The Engine That Does More</content>
        
</field>
        
<field key="link">
          
<content>http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp</content>
        
</field>
        
<field key="description">
          
<content>Before man travels to Mars, NASA hopes to design new engines that will let us fly through the Solar System more quickly.  The proposed VASIMR engine would do that.</content>
        
</field>
        
<field key="guid">
          
<content>http://liftoff.msfc.nasa.gov/2003/05/27.html#item571</content>
        
</field>
        
<field key="__Publish">
          
<content>20030527T113732</content>
        
</field>
      
</fields>
    
</version>
  
</item>
</items>

The root element of this document is <items>. This element represents a parent element for all external Items. Below the <items> you can see a list of <field> tags. These fields can be shown as additional information for Sitecore native Items (the Items created internally in Sitecore). If a Template for Sitecore native Items contains fields, names of which coincide with the values of key attribute of the field tags, then the value of this tag will be put into the corresponding field of the Sitecore Item.

For example, if you want to insert the field value of with the 'key=’link’'attribute, then a base Template for your Sitecore Item should contain a field with the name ‘link’.

After <field> tags, there go <item> tags. These are the descriptions of the Items which will be shown in the Sitecore content tree. Items must hold the <version> tag and may contain other <item> tags (which will be interpreted as children). An Item tag must contain two attributes: a name (the Item's name in the Sitecore content tree) and an id (id then identifies the current Item). The ID should be of string type.

Version tag represents the version of an Item. The required attributes are a language and a version. After this tag, there go <field> tags which describe the current Item’s fields .

If your XMLsource does not match the structure above, you can transform it using your own class which should implement the IExternalSourceTransformer class (see the section below for more information about data transformation).

The current package includes a base Template for all external sources which should be processed by the XML data provider. See the picture below for more information:

The base Template for external sources consists of four fields:

All Templates which are supposed to be populated from the external source should be based on the External Source Template. For example, a package includes Templates for RSS data sources: the Rss External Source Template which is based on the External Source Template, and the RssItem Template which is used to represent Items in RSS data format.

5.  User Manual

To use the XML data provider for the external source integration, you should create an Item based on a Template which derives from the External Source Template. For example, if you want to import the rss atom feed into Sitecore, you can choose the RSS External Source Template as a base Template for the parent Item or create an Item based on the RSS External Source Master.  To configure the XML data provider to work with the RSS format, you should fill in the main parameters, as shown in the picture below:

 

According to the picture above, the Item will refresh its data every 300 seconds. Data for the Rss External Source Folder will be fetched from http://runithomsen.blogspot.com/atom.xml.

The Item shown in Sitecore content tree is based on the RssItemTemplate. The last field specifies a transformer used to transform the RSS data to the required data structure.

More information about RSS can be found here: http://blogs.law.harvard.edu/tech/rss

If you expand the ‘External Data’ section, you will see additional information for the RSS feed:

 

If all options are set correctly and you are connected to the Internet, then you will be able to expand a parent Item and view the RSS feed Items:

 

 

6.  Transformation in Depth

Your custom class which transforms the source to the required XML format should implement the IExternalSourceTransformer interface, which defines two methods:  

      bool CanTransform(string source);

      string Transform(string source);

The Transform method should transform a raw source to the format recognized by the XML Data provider.

For XML generation, you can also use classes from Sitecore.Data.ExternlSource.Serialization: 

To generate XML which will be used as a source for the XML data provider, you should create an appropriate hierarchy of these classes and serialize them with ExternalItemSerializer which shares the same namespace.